<?php

// Prevent individual file access
if (!defined('DIR_BASE'))
	exit ;

class UserController {

	private $usermodel;
	public static $userid;

	public function login() {
		$username = Request::getVar('username');
		$password = Request::getVar('password');
		$passwordEncrypted = md5($password);
		$userrow = $this -> usermodel -> get($username, $passwordEncrypted);
		if (!empty($userrow)) {
			self::$userid = $userrow['id'];
			return true;
		} else {
			return false;
		}
	}

	public function logout() {

	}

	public function edit() {
		$password = Request::getVar('password');
		$passwordEncrypted = md5($password);
		$values = array(
			'password' => $passwordEncrypted, 
			'username' => Request::getVar('username'), 
			'realname' => Request::getVar('realname'), 
			'authority' => Request::getVar('authority'), 
			'parent' => Request::getVar('parent')
		);
		$userid = Request::getVar('userid');
		if ($userid != 0) {
			$values['id'] = $userid;
		}
		$this -> usermodel -> edit($values);
	}

}
?>